package com.x.erp.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.x.erp.thirdparty.ZhiTongInfo;
import com.x.framework.remote.HttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ZhiTongApi {

	private Logger logger = LoggerFactory.getLogger(this.getClass());

	@Autowired
	private HttpClient httpClient;

	/**
	 * 用户信息同步
	 * @param zhiTongInfo
	 * @return
	 * @throws Exception
	 */
	public ZhiTongResult insertShop(ZhiTongInfo zhiTongInfo) throws Exception{
		logger.info("智通请求数据：" + JSON.toJSONString(zhiTongInfo));
		String result = httpClient.doPostJson(Constant.ZHITONG_INSERT_USER_URL, JSON.toJSONString(zhiTongInfo));
		logger.info("智通返回数据：" + new String(result.getBytes(), "UTF-8"));
		if ("".equals(result)){
			return null;
		}
		return JSONObject.parseObject(result, ZhiTongResult.class);
	}
}
